#!/usr/bin/env python

#to represent a profile file
import ConfigParser
import os

class SystemConfig:
    
    def __init__(self):
        
        system_config = ConfigParser.ConfigParser()
        system_config.read('system.ini')
        
        self.mode = system_config.getint("sys", "mode")
        
        self.telnet_debug_level = system_config.getint("telnet", "telnet_debug_level")
        self.telnet_timeout = system_config.getint("telnet", "telnet_timeout")
        self.ftp_buffer_size = system_config.getint("ftp", "ftp_buffer_size")
        self.ftp_debug_level = system_config.getint("ftp", "ftp_debug_level")
        self.ftp_default_debug_level = system_config.getint("ftp", "ftp_default_debug_level")

    def get_mode(self):
        
        return self.mode        
    
    def get_telnet_debug_level(self):
        
        return self.telnet_debug_level

    def get_telnet_timeout(self):
        
        return self.telnet_timeout
    
    def get_ftp_buffer_size(self):
        
        return self.ftp_buffer_size
    
    def get_ftp_debug_level(self):
        
        return self.ftp_debug_level
    
    def get_ftp_default_debug_level(self):
        
        return self.ftp_default_debug_level

class Profile:
    
    def __init__(self, id):
        
        self.id=id
        
        #read the config file
        sep = os.path.sep
        config = ConfigParser.ConfigParser()
        
        config.read('profiles'+sep+self.id + '.ini')
        
        #get the section type of the profile
        self.section = config.sections()[0]
        
        if self.section == 'WAS':
            
            #get the type of the profile
            type = self.config_type = config.get(self.section, 'type')
            
            #get the host name of the profile
            self.config_host = config.get(self.section, 'host')
    
            #get the host name of the profile
            self.config_system = config.get(self.section, 'system')
            
            #get the method to communicate with the server
            self.config_user = config.get(self.section, 'user')
            
            #get the method to communicate with the server
            self.config_passwd = config.get(self.section, 'passwd')
            
            #get the name of the profle
            self.config_name = config.get(self.section, 'name')
            
            #get the home of the websphere
            self.config_home = config.get(self.section, 'home')
            
            #get the method to communicate with the server
            self.config_comm = config.get(self.section, 'comm')
            
            #get the download way to the server
            self.config_download = config.get(self.section, 'download')
            
            #get the download user name
            self.config_duser = config.get(self.section, 'duser')
            
            #get the download user password
            self.config_dpasswd = config.get(self.section, 'dpasswd')
            
            #get the port of FTP
            self.config_ftpport = config.get(self.section, 'ftpport')
            
            if type == 'SERVER' or type == 'S_SERVER':          
                
                #get the name of the server
                self.config_server = config.get(self.section, 'server')
            
            if type == 'S_DMGR' or type == 'S_NODE' or type == 'S_SERVER':
                
                #get the user of the web admin
                self.config_web_admin_user = config.get(self.section, 'web_admin_user')
                
                #get the password of the web admin
                self.config_web_admin_pass = config.get(self.section, 'web_admin_pass')

        if self.section == 'TOMCAT':
            
            
            #get the host name of the profile
            self.config_host = config.get(self.section, 'host')
    
            #get the host name of the profile
            self.config_system = config.get(self.section, 'system')
            
            #get the method to communicate with the server
            self.config_user = config.get(self.section, 'user')
            
            #get the method to communicate with the server
            self.config_passwd = config.get(self.section, 'passwd')
            
            #get the home of the websphere
            self.config_home = config.get(self.section, 'home')
            
            #get the method to communicate with the server
            self.config_comm = config.get(self.section, 'comm')
            
            #get the download way to the server
            self.config_download = config.get(self.section, 'download')
            
            #get the download user name
            self.config_duser = config.get(self.section, 'duser')
            
            #get the download user password
            self.config_dpasswd = config.get(self.section, 'dpasswd')
            
            #get the port of FTP
            self.config_ftpport = config.get(self.section, 'ftpport')        
                       
        elif self.section == 'APACHE':
            
            #get the host name of the profile
            self.config_host = config.get(self.section, 'host')
    
            #get the host name of the profile
            self.config_system = config.get(self.section, 'system')
            
            #get the method to communicate with the server
            self.config_user = config.get(self.section, 'user')
            
            #get the method to communicate with the server
            self.config_passwd = config.get(self.section, 'passwd')
    
            #get the home of the apache
            self.config_home = config.get(self.section, 'home')
            
            #get the method to communicate with the server
            self.config_comm = config.get(self.section, 'comm')

            #get the download way to the server
            self.config_download = config.get(self.section, 'download')
            
            #get the download user name
            self.config_duser = config.get(self.section, 'duser')
            
            #get the download user password
            self.config_dpasswd = config.get(self.section, 'dpasswd')
            
            #get the port of FTP
            self.config_ftpport = config.get(self.section, 'ftpport')
            
        elif self.section == 'DB2':

            #get the host name of the profile
            self.config_host = config.get(self.section, 'host')
    
            #get the host name of the profile
            self.config_system = config.get(self.section, 'system')
            
            #get the method to communicate with the server
            self.config_user = config.get(self.section, 'user')
            
            #get the method to communicate with the server
            self.config_passwd = config.get(self.section, 'passwd')
            
            #get the method to communicate with the server
            self.config_comm = config.get(self.section, 'comm')         
            
        
        elif self.section == 'AIX':
            
            #get the host name of the profile
            self.config_host = config.get(self.section, 'host')
    
            #get the host name of the profile
            self.config_system = config.get(self.section, 'system')
            
            #get the method to communicate with the server
            self.config_user = config.get(self.section, 'user')
            
            #get the method to communicate with the server
            self.config_passwd = config.get(self.section, 'passwd')
            
            #get the method to communicate with the server
            self.config_comm = config.get(self.section, 'comm')
            
            #get the download way to the server
            self.config_download = config.get(self.section, 'download')
            
            #get the download user name
            self.config_duser = config.get(self.section, 'duser')
            
            #get the download user password
            self.config_dpasswd = config.get(self.section, 'dpasswd')
            
            #get the port of FTP
            self.config_ftpport = config.get(self.section, 'ftpport')            
            
        
        elif self.section == 'SUIT':
            
            #get the profile array
            self.profiles = config.get(self.section, 'profiles').split(",")
    
            #get the action array
            self.actions = config.get(self.section, 'actions').split(",")
        
    
    def get_section(self):
        
        return self.section
             
    def get_id(self):
        
        return self.id
    
    def get_type(self):
        
        return self.config_type
    
    def get_host(self):
        
        return self.config_host

    def get_system(self):
        
        return self.config_system

    def get_user(self):
        
        return self.config_user

    def get_passwd(self):
        
        return self.config_passwd

    def get_name(self):
        
        return self.config_name

    def get_server(self):
        
        return self.config_server

    def get_home(self):
        
        return self.config_home

    def get_comm(self):
        
        return self.config_comm
    
    def get_profiles(self):
        
        return self.profiles
    
    def get_actions(self):
        
        return self.actions
    
    def get_download(self):
        
        return self.config_download
    
    def get_duser(self):
        
        return self.config_duser
    
    def get_dpasswd(self):
        
        return self.config_dpasswd
    
    def get_ftpport(self):
        
        return self.config_ftpport
    
    def get_web_admin_user(self):
        
        return self.config_web_admin_user
    
    def get_web_admin_pass(self):
        
        return self.config_web_admin_pass

    